﻿
@{
    ViewBag.Title = "Index";
}

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 房源管理 <span class="c-gray en">&gt;</span> 房源列表 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="pd-20">
    <table id="tb_HouseList" class="table table-border table-bordered table-bg">
        <thead>
            <tr>
                <th scope="col" colspan="10">预约看房列表</th>
            </tr>
            <tr class="text-c">
                <th width="150">姓名</th>
                <th width="90">电话</th>
                <th width="90">预约时间</th>
                <th width="90">看房时间</th>
                <th width="90">小区</th>
                <th width="90">地址</th>
                <th width="90">状态</th>
                <th width="90">跟进员工</th>
                <th width="100">接单</th>
            </tr>
        </thead>

    </table>

</div>

@section footScript
{
    <script src="~/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
    <script>


        var params = {};

        $(function () {


            var table = $("#tb_HouseList").DataTable({
                pagingType: "full_numbers",//显示首页尾页
                processing: true, //显示加载中提示....
                ordering: false,//是否排序
                paging: true,//是否显示分页
                searching: false,//是否显示默认的搜索
                //使用对象数组，一定要配置columns，告诉 DataTables 每列对应的属性
                columns: [

                    { data: 'Name' },
                    { data: 'PhoneNum' },
                    {
                        data: 'CreateDateTime', render: function (data, type, full, callback) {
                            return FormatJsonTime(data);
                        }
                    },
                    {
                        data: 'VisitDate', render: function (data, type, full, callback) {
                            return FormatJsonTime(data);
                        }
                    },
                    { data: 'CommunityName' },
                    { data: 'HouseAddress' },
                    { data: 'Status' },
                    { data: 'FollowAdminUserName' },
                    {
                        data: 'Id', render: function (data, type, full, callback) {
                            return ('<a title="抢单" href="javascript:;" data-id="' + data + '" class="ml-5 follow" style="text-decoration:none"><i class="Hui-iconfont">&#xe6d0;</i></a>')
                        }
                    }

                ],
                createdRow: function (row, data, index) {
                    /* 设置表格中的内容居中 */
                    $('td', row).attr("class", "text-c");
                },
                //开启服务器模式
                serverSide: true,
                //使用ajax异步请求
                ajax: {
                    type: 'POST',
                    url: '/HouseAppointment/GetList',
                    data: function (d) {

                        params.start = d.start;//开始的序号
                        params.length = d.length;//要取的数据的条数
                        return params;//自定义需要传递的参数。
                    }
                },
                //columnDefs: [{
                //    targets: 0,
                //    render: function (data, type, row, meta) {
                //        return '<input type="checkbox" value="' + row.Id + '" name="selectRoleIDs">';
                //    }
                //}
                //    // { "orderable": false, "targets": 4 },
                //]
            });


            //抢单
            $(".follow").livequery("click", function () {
                var id = $(this).attr("data-id");
                $.post("/HouseAppointment/Follow", { Id: id }, function (data) {
                    if (data.State == 1) {
                        //弹出提示信息
                        layer.msg('添加成功', { icon: 1 }, function () {
                            //关闭遮罩层
                            //刷新列表
                            location.reload();
                        });
                    }
                    else {
                        layer.msg(data.ErrorMessage, { icon: 5 });
                    }
                }, "json");
            });
        })


        //格式化JSON时间
        function FormatJsonTime(date) {
            if (date != null) {
                var de = new Date(parseInt(date.replace("/Date(", "").replace(")/", "").split("+")[0]));
                var y = de.getFullYear();
                var m = de.getMonth() + 1;
                var d = de.getDate();
                var h = de.getHours();
                var mi = de.getMinutes();
                var s = de.getSeconds();
                return y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d) + ' ' + (h < 10 ? ('0' + h) : h) + ':' + (mi < 10 ? ('0' + mi) : mi) + ':' + (s < 10 ? ('0' + s) : s);
            }
            else {
                return "";
            }
        }

    </script>
}

